﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using ATSL.ADOComponents;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ATSL.ADOComponenets.Tests
{
    [TestClass]
    public class DataServiceCommandTest
    {
        [TestMethod]
        public void SelectCommandTest()
        {
            using (DataServiceCommand dsCmd = new DataServiceCommand())
            {
                //set data service entity URI. i.e http://localhost/TestDataService/TestDataService.svc/Products
                dsCmd.EntityUri = "http://localhost/TestDataService/TestDataService.svc/Products";

                //data service query that get all entites (products) that contains "Sample Product 1" in the name property
                //this should return one item only from the test db
                //for a full list of data service quries http://www.odata.org/developers/protocols/uri-conventions , Section 4
                dsCmd.CommandText = "?$filter=substringof('Sample Product 1',Name) eq true";
                DataServiceDataReader reader = (DataServiceDataReader) dsCmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string readerResult = string.Format("Product Id: {0}, Product Name: {1}", reader.GetInt32(0), reader.GetString(1));
                        Assert.AreEqual(readerResult, "Product Id: 1, Product Name: Sample Product 1");
                    }
                }
                    else
                {
                    throw new Exception("DataServiceCommand.ExecuteReader returned an empty reader");
                }

            }
        }

        [TestMethod]
        public void InsertCommandTest()
        {
        }

        [TestMethod]
        public void DeleteCommandTest()
        {
        }

    }
}
